package com.ruoyi.durian.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.durian.domain.LlCardPackage;
import com.ruoyi.durian.domain.dto.ThaliInfoDto;
import com.ruoyi.durian.service.LlCardPackageService;
import com.ruoyi.durian.mapper.LlCardPackageMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author lenovo
 * @description 针对表【ll_card_package(个人中心-用户购买的优惠券表)】的数据库操作Service实现
 * @createDate 2024-07-26 16:17:15
 */
@Service
public class LlCardPackageServiceImpl extends ServiceImpl<LlCardPackageMapper, LlCardPackage>
        implements LlCardPackageService {

    @Resource
    private LlCardPackageMapper llCardPackageMapper;

    /**
     * 失效券列表
     *
     * @return
     */
    @Override
    public List<ThaliInfoDto> selectList() {
        Integer userId = SecurityUtils.getUserId().intValue();
        List<ThaliInfoDto> thinfo = llCardPackageMapper.selectMyCard(userId);
        return thinfo;
    }

    /**
     * 定时任务检查失效优惠券
     */
    @Override
    public Boolean checkLoseEfficacyCoupon() {
        LambdaUpdateWrapper<LlCardPackage> update = new LambdaUpdateWrapper<>();
        update.gt(LlCardPackage::getEndTime, LocalDateTime.now());
        update.eq(LlCardPackage::getStatus, 0);
        update.set(LlCardPackage::getStatus, 1);
        return update(update);
    }
}




